package com.itheima.consultant.mapper;

import com.itheima.consultant.entity.ChatHistory;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface ChatHistoryMapper {

    @Insert("INSERT INTO chat_history (user_id, question, answer) VALUES (#{userId}, #{question}, #{answer})")
    void save(@Param("userId") String userId, @Param("question") String question, @Param("answer") String answer);

    @Select("SELECT * FROM chat_history WHERE user_id = #{userId} ORDER BY created_time DESC")
    List<ChatHistory> findByUserId(@Param("userId") String userId);
}